let { jwt, jwtKey } = require('../server_jwt');
let express = require('express');
let router = express.Router();
let db = require('../db');


router.get('/all', (req, res) => {
    const token = req.headers['authorization'];
    jwt.verify(token, jwtKey, (err, decoded) => {
        if (err) {
            return res.send({msg: "登录验证失败，请重新登录", login: false});
        } else if (parseInt(+new Date() / 1000) >= decoded.exp) {
            return res.send({msg: "登录超时:", login: false});
        }
        db.query('select username, intor, imgList, postID from post p join users u where p.uid = u.uid order by createTime desc', (err, result) => {
            if (err) {
                // console.log(err.message);
                res.status(500).send('Server Error'); // 发送500服务器错误状态码及简单错误消息
            } else {
                // console.log(result);
                res.status(200).json(result); // 使用JSON格式发送查询结果，并设置200状态码
            }
        })
    });
});

module.exports = router;
